package com.smart.controller;

import java.util.List;
import com.smart.util.Messages;
import io.swagger.annotations.Api;
import com.smart.service.FileService;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.Autowired;

@RestController
@RequestMapping("/file")
@Api(tags="文件管理")
public class FileController extends BaseController{

    @Autowired
    private FileService fileService;

    /**
     * 上传图片
     * @param files
     * @return
     **/
    @ApiOperation(value="上传图片",notes="上传图片")
    @RequestMapping(value="/upload/pic",method=RequestMethod.POST)
    public Messages<List<String>> uploadPic(@ApiParam(value="图片",type="file",required=true)
           @RequestParam(value="files",required=false) MultipartFile[] files) {
        return Messages.success(fileService.uploadPic(files));
    }

    /**
     * 删除图片/文件
     * @param sourcePath
     * @return
     **/
    @ApiOperation(value="删除图片",notes="删除图片")
    @RequestMapping(value="/remove/pic",method=RequestMethod.DELETE)
    public Messages<Integer> removePicAndFile(String sourcePath){
        return Messages.success(fileService.removePicAndFile(sourcePath));
    }

}